package com.hq.fxh.No2_BBS.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hq.fxh.No0_ChengQu.Login.LoginActivity;
import com.hq.fxh.No2_BBS.Activity.PlateEditorActivity;
import com.hq.fxh.No2_BBS.Adapter.Padapter_BBS;
import com.hq.fxh.No0_ChengQu.Fragment.BaseFragment;
import com.hq.fxh.R;
import com.hq.fxh.Utils.AppConstant;
import com.hq.fxh.Utils.LogUtils;
import com.hq.fxh.CustomerView.NoScrollViewPager;
import com.hq.fxh.Utils.SharedPreferenceUtils;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :论坛框架
 * @Created 2017/8/17
 * @Email xlwenhao1858@sina.com
 */


public class Fragment_BBS extends BaseFragment implements View.OnClickListener {
    protected View rootView;
    protected LinearLayout layoutBBSFaTie;
    protected NoScrollViewPager viewPagerBbs;
    protected TextView tvBBSGuidePost;
    protected TextView tvBBSGuidePlate;

/*

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        LogUtils.e("bbs_ onCreateView");
        rootView = inflater.inflate(, null);
        return rootView;
    }
*/

    @Override
    public int getLayoutId() {
        return R.layout.fragment_bbs;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void findView(View rootView) {
        layoutBBSFaTie = (LinearLayout) rootView.findViewById(R.id.layout_BBS_FaTie);
        layoutBBSFaTie.setOnClickListener(Fragment_BBS.this);
        viewPagerBbs = (NoScrollViewPager) rootView.findViewById(R.id.viewPager_bbs);
        viewPagerBbs.setAdapter(new Padapter_BBS(getChildFragmentManager()));
        tvBBSGuidePost = (TextView) rootView.findViewById(R.id.tv_BBS_Guide_Post);
        tvBBSGuidePost.setOnClickListener(Fragment_BBS.this);
        tvBBSGuidePlate = (TextView) rootView.findViewById(R.id.tv_BBS_Guide_Plate);
        tvBBSGuidePlate.setOnClickListener(Fragment_BBS.this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.layout_BBS_FaTie) {
            if (SharedPreferenceUtils.getMemberId(getContext()) == 0) {
                LogUtils.startToash(getContext(), AppConstant.PleaseLogin);
            } else {
                startActivity(new Intent(getContext(), PlateEditorActivity.class));

            }

        } else if (view.getId() == R.id.tv_BBS_Guide_Post) {
            viewPagerBbs.setCurrentItem(0);
            changeGuide(tvBBSGuidePlate, false, false);
            changeGuide(tvBBSGuidePost, true, true);


        } else if (view.getId() == R.id.tv_BBS_Guide_Plate) {
            viewPagerBbs.setCurrentItem(1);
            changeGuide(tvBBSGuidePlate, true, false);
            changeGuide(tvBBSGuidePost, false, true);

        }
    }

    public void changeGuide(TextView textView, boolean isSelect, boolean isLeft) {

        if (isSelect) {
            if (isLeft) {
                textView.setBackgroundResource(R.drawable.style_switchbth_left_on);

            } else {
                textView.setBackgroundResource(R.drawable.style_switchbth_right_on);

            }
            textView.setTextColor(getResources().getColor(R.color.white));

        } else {
            if (isLeft) {
                textView.setBackgroundResource(R.drawable.style_switchbth_left);
            } else {
                textView.setBackgroundResource(R.drawable.style_switchbth_right);
            }
            textView.setTextColor(getResources().getColor(R.color.red));
        }


    }


}
